/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.ipti.br.tag.bo;

import org.ipti.br.tag.dao.ActorFacade;
import org.ipti.br.tag.dao.ActorScheduleFacade;
import org.ipti.br.tag.entity.Actor;
import org.ipti.br.tag.entity.ActorSchedule;
import org.ipti.br.tag.entity.Discipline;
import org.ipti.br.tag.entity.UnitySchedule;
import org.ipti.br.tag.entity.enums.Reference;
import org.ipti.br.tag.entity.enums.WeekDay;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.inject.Inject;
import javax.ejb.Stateless;
import javax.persistence.NoResultException;

/**
 *
 * @author root
 */
@Stateless
public class ActorScheduleBO implements Serializable {

    @Inject
    private ActorScheduleFacade actorScheduleDAO;
    
    @Inject
    private ActorFacade actorFacade;

    public ActorScheduleFacade getActorScheduleDAO() {
        return actorScheduleDAO;
    }

    public void create(ActorSchedule actorSchedule) {
        getActorScheduleDAO().create(actorSchedule);
    }

    public void createOrUpdate(Actor actor, UnitySchedule unitySchedule) {
        ActorSchedule actorSchedule = find(unitySchedule, actor);
        
        if (actorSchedule == null){
            getActorScheduleDAO().create(new ActorSchedule(unitySchedule, actor));
        } else {
            getActorScheduleDAO().edit(actorSchedule);
        }
    }

    public void edit(ActorSchedule actorSchedule) {
        getActorScheduleDAO().edit(actorSchedule);
    }

    public void remove(ActorSchedule actorSchedule) {
        getActorScheduleDAO().remove(actorSchedule);
    }

    public ActorSchedule find(Object id) {
        return getActorScheduleDAO().find(id);
    }
    
    public ActorSchedule find(UnitySchedule unitySchedule, Actor actor) throws NoResultException{
        return getActorScheduleDAO().find(unitySchedule, actor);
    }

    public List<ActorSchedule> findAll() {
        return getActorScheduleDAO().findAll();
    }

    public void editForSynchronization(ActorSchedule actorSchedule) {
        getActorScheduleDAO().editForSynchronization(actorSchedule);
    }
    
    public void remove(Actor actor, UnitySchedule schedule){
        ActorSchedule actorSchedule = find(schedule, actor);
        remove(actorSchedule);
    }

    public void remove(UnitySchedule schedule) {
        for (Actor a : actorFacade.listAllocateds(schedule)) {
            remove(a,schedule);
            actorFacade.remove(a);
        }
    }
}
